﻿using G.Service.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace G.Service.BLL
{
    public static class PushInfoBLL
    {
        //public static Result AddPushInfo(string deviceid)
        //{
        //    if (string.IsNullOrEmpty(deviceid))
        //    {
        //        return new Result() { Msg = "设备id不能为空" };
        //    }
        //    Data.PushInfoData data = new Data.PushInfoData();
        //    if(data.
        //}

        public static Result UpdatePushInfo(string deviceid, string platform, string pushurl)
        {
            if (string.IsNullOrEmpty(deviceid))
            {
                return new Result() { Msg = "设备id不能为空" };
            }
            G.Service.Data.PushInfoData data = new G.Service.Data.PushInfoData();
            var temp = data.GetPushInfoByDeviceId(deviceid);
            if (temp == null)
            {
                if (string.IsNullOrEmpty(platform))
                {
                    return new Result() { Msg = "缺少平台号" };
                }
                data.AddPushInfo(deviceid, platform, pushurl);
            }
            else
            {
                data.UpdatePushInfo(temp, pushurl);
            }
            data.SaveChanges();
            return new Result() { IsOK = true };
        }

        public static Result<PushInfo[]> GetALLPushInfos()
        {
            G.Service.Data.PushInfoData data = new G.Service.Data.PushInfoData();

            return new Result<PushInfo[]>() { ResponseData = data.GetALLPushInfos().ToArray(), IsOK = true };
        }
    }
}
